from flask import Blueprint
from peewee import DoesNotExist

from app.advices.urls import bp as advice_bp
from app.auth.urls import bp as auth_bp
from app.extensions import json_response
from app.text.urls import bp as text_bp
from app.version.urls import bp as version_bp

base_bp = Blueprint("main", __name__, url_prefix="/api")


@base_bp.errorhandler(DoesNotExist)
def handle_not_exist(error):
    return json_response(code=404, data={"msg": "no record"})


@base_bp.errorhandler(Exception)
def handle_exception(error):
    return json_response(code=500, data={"msg": error})


base_bp.register_blueprint(version_bp)
base_bp.register_blueprint(text_bp)
base_bp.register_blueprint(auth_bp)
base_bp.register_blueprint(advice_bp)
